﻿using Hxj.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utility.Comm
{
    /// <summary>
    /// 分页查询信息
    /// </summary>
    [Serializable]
    public class PagerCondition
    {
        #region 私有变量
        private int _RecordCount = -1;
        private int _PageSize = 10;
        private int _CurrentPage = -1;
        private WhereClip _ComplexSearchCondition;
        private OrderByClip _OrderBy;
        private string _SortExpression = string.Empty;
        private string _SortDirection = string.Empty;
        private string _strDataJson = string.Empty;
        private string _OtherData = string.Empty;
        #endregion

        #region 公共属性
        /// <summary>
        /// 其它数据
        /// </summary>
        public string OtherData
        {
            get { return _OtherData; }
            set { _OtherData = value; }
        }
        /// <summary>
        /// DataTable数据,Json格式
        /// </summary>
        public string DataJson
        {
            get { return _strDataJson; }
            set { _strDataJson = value; }
        }

        /// <summary>
        /// 排序表达式
        /// </summary>
        public string SortExpression
        {
            get { return _SortExpression; }
            set { _SortExpression = value; }
        }

        /// <summary>
        /// 排序方向
        /// </summary>
        public string SortDirection
        {
            get { return _SortDirection; }
            set { _SortDirection = value; }
        }
        /// <summary>
        /// 总记录数
        /// </summary>
        public int RecordCount
        {
            get
            {
                return _RecordCount;
            }
            set
            {
                _RecordCount = value;
            }
        }

        /// <summary>
        /// 总页数
        /// </summary>
        public int PageCount
        {
            get
            {
                if (PageSize > 0)
                    return ((RecordCount - 1) / PageSize) + 1;
                return 1;
            }

        }

        /// <summary>
        /// 每页记录数
        /// </summary>
        public int PageSize
        {
            get
            {
                return _PageSize;
            }
            set
            {
                _PageSize = value;
            }
        }

        /// <summary>
        /// 当前页
        /// </summary>
        public int CurrentPage
        {
            get
            {
                return _CurrentPage;
            }
            set
            {
                _CurrentPage = value;
            }
        }

        /// <summary>
        /// 检索条件
        /// </summary>
        public WhereClip ComplexSearchCondition
        {
            get
            {
                if (_ComplexSearchCondition == null)
                {
                    _ComplexSearchCondition = new WhereClip();
                }
                return _ComplexSearchCondition;
            }
            set
            {
                _ComplexSearchCondition = value;
            }
        }

        /// <summary>
        /// 排序条件
        /// </summary>
        public OrderByClip OrderBy
        {
            get
            {
                return _OrderBy;
            }
            set { _OrderBy = value; }
        }

        #endregion
    }
}
